<?php

namespace App\Admin\Controllers;

use App\Models\PayTemplets;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class PayTempletsController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(PayTemplets::class, function (Grid $grid) {
            $grid->disableExport();

            $grid->id('ID');
            $grid->column('name','模板名字');
            $grid->column('amount','金额');
            $grid->column('coin','可兑换的金币');

            $states = [
            		'on'  => ['value' => 'enabled', 'text' => '打开', 'color' => 'success'],
            		'off' => ['value' => 'disabled', 'text' => '关闭', 'color' => 'danger'],
            ];
            $grid->status()->switch($states);
            
            $grid->created_at('添加时间');
            $grid->updated_at('最修改时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(PayTemplets::class, function (Form $form) {

        	$states = [
        			'on'  => ['value' => 'enabled', 'text' => '打开', 'color' => 'success'],
        			'off' => ['value' => 'disabled', 'text' => '关闭', 'color' => 'danger'],
        	];
        	
        	
            $form->display('id', 'ID');

            $form->text('name','模板名字');
            $form->currency('amount','金额')->symbol('￥');
            $form->number('coin','可兑换的兑换金币');
            
            $form->switch('status','状态')->states($states);
            $form->display('created_at', '添加时间');
            $form->display('updated_at', '更新时间');
        });
    }
}
